package com.webside.points.controller;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;
import com.webside.points.model.UserPostEntity;
import com.webside.points.service.UserPostService;

@Controller
@Scope("prototype")
@RequestMapping("/userPost/")
public class UserPostController {

	@Autowired
	UserPostService userPostService;
	
	@RequestMapping("findByUserId")
	public void findByUserId(int userId,int postTypeId,HttpServletResponse response){
		
		UserPostEntity userPost = new UserPostEntity();
		userPost.setUserId(userId);
		userPost.setPostTypeId(postTypeId);
		UserPostEntity userPostEntity = userPostService.findByUserId(userPost);
		
		String json = JSON.toJSONString(userPostEntity);
		try {
			response.getWriter().write(json);
			response.flushBuffer();
		} catch (Exception e) {
			System.out.println("JsonError："+e);
		}
		
	}
}
